import { defineStore } from 'pinia'
import { getMenuList } from '@/api/login'
import { addRoute } from './addRoute'

export const useMenuStore = defineStore('menu', {
  state: () => ({
    menu: []
  }),
  actions: {
    getMenu() {
      return getMenuList().then((res: any) => {
        let list = res.list
        this.saveMenu(list)
      })
    },
    saveMenu(val: any) {
      this.menu = val
      // 生成动态路由
      addRoute(val)
      // console.log(this.menu)
    }
  }
})
